package com.itheima.controller;

import com.itheima.pojo.CheckItem;
import com.itheima.pojo.PageBean;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/checkitem")
public class checkItemController {
    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/findPage")
    public Map<String,Object> selectfindPage(@RequestBody PageBean pageBean){
        return checkItemService.selectfindPage(
                pageBean.getCurrentPage(),
                pageBean.getPageSize(),
                pageBean.getQueryString()
        );
    }
















    @RequestMapping("/add")
    public Map<String,Object> add(@RequestBody CheckItem checkItem){
        checkItemService.add(checkItem);
        Map<String, Object> map = new HashMap<>();
        map.put("data",null);
        map.put("flag",true);
        map.put("message","新增检查项成功");
        return map;
    }

    @GetMapping("/delete")
    public Map<String,Object> delete(@RequestParam Integer id){
        checkItemService.delete(id);
        Map<String, Object> map = new HashMap<>();
        map.put("data",null);
        map.put("flag",true);
        map.put("message","删除检查项成功");
        return map;
    }

    @GetMapping("/findById")
    public Map<String,Object> findById(@RequestParam Integer id){
        CheckItem checkItem = checkItemService.findById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("data",checkItem);
        map.put("flag",true);
        map.put("message","查询检查项成功");
        return map;
    }

    @PostMapping("/edit")
    public Map<String,Object> edit(@RequestBody CheckItem checkItem){
        checkItemService.edit(checkItem);
        Map<String, Object> map = new HashMap<>();
        map.put("data",checkItem);
        map.put("flag",true);
        map.put("message","编辑检查项成功");
        return map;
    }
}
